<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box" style="width: 400rpx;">
				<u-tabs-swiper class="tabs-swiper1" :offset="[9,10]"
					:active-item-style="{fontSize: '34rpx', color: '#21D2FF' }" :show-bar=false :item-width=90
					activeColor="#4D5B80" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false"
					:dotStyle="{showDot:true, dotColor:'warning'}"></u-tabs-swiper>
			</view>
			<view class="follow-count">
				总数：{{attentionList.length}}
			</view>
			<u-line :hair-line=true style="width: 692rpx;" color="#949494" margin="0 auto"></u-line>
			<swiper class="swiper-box" v-if="attentionList.length" :current="swiperCurrent"
				@change="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order">
								<view class="item" v-for="(item, index) in attentionList" :key="index" @click="goToLink(item)">
									<view class="left" >
										<u-avatar level-size="90" :level-icon="item.starFlag === '1' ? '/static/img/community/ic_daka.png' : ''"
											show-level=true mode="circle" :src="img_url + item.avatar" img-mode="aspectFill">
										</u-avatar>
									</view>
									<view class="content">
										<view class="title-line u-line-2">
											<view class="title">{{ item.nickName }}</view>
										</view>
										<view class='info-line'>
											<text>{{item.intro}}</text>
										</view>
									</view>
									<view class="right">
										<u-follow-button @clkFollow="clkFollowData(item)" :itemData="item" :type=1 :isFollowed="item.attentionFlag !== '1' ? false : true">
										</u-follow-button>
									</view>
								</view>
							</view>
							<u-loadmore :status="loadStatus[0]" bgColor="#ffffff"></u-loadmore>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order">
								<view class="item" v-for="(item, index) in attentionList" @click="goToLink(item)" :key="index">
									<view class="left">
										<u-avatar level-size="90" :level-icon="item.starFlag === '1' ? '/static/img/community/ic_daka.png' : ''"
											show-level=true mode="circle" :src="img_url + item.avatar" img-mode="aspectFill">
										</u-avatar>
									</view>
									<view class="content">
										<view class="title-line u-line-2">
											<view class="title">{{ item.nickName }}</view>

										</view>
										<view class='info-line'>
											<text>{{item.intro}}</text>
										</view>
									</view>

									<view class="right">
										<u-follow-button @clkFollow="clkFollowData(item)" :itemData="item" :type=2 :isFollowed="item.attentionFlag !== '1' ? false : true">
										</u-follow-button>
									</view>
								</view>
							</view>
							<u-loadmore :status="loadStatus[0]" bgColor="#ffffff"></u-loadmore>
						</view>
					</scroll-view>
				</swiper-item>

			</swiper>
				<view class="no-data-wrapper" v-if="!attentionList.length && noDataFlag">
				<img class="no-image" src="/static/img/attention_no.png" alt="" srcset="">
				<view class="text-top">暂无关注</view>
				<view class="text-bottom">您还没有关注的人</view>
			</view>
		</view>
	</view>
</template>

<script>
	import apis from '@/apis.js'
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				noDataFlag: false,
				isFollow: true,
				list: [{
						name: '我关注的人'
					},
					{
						name: '关注我的人'
					}
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				followCount: 4,
				loadStatus: ['loadmore', 'loadmore'],
				attentionList: [],
				listQuery: {
					type: 1,
					pageNo: 1,
					pageSize: 10
				}
			};
		},
		onLoad() {
			this.getList()
		},
		computed: {
			...mapState(['img_url']),
		},
		methods: {
			goToLink(item) {
				uni.navigateTo({
					url: '/pages/tabbar/tabbar-1/personHome?id=' + item.id 
				})
			},
			getList() {
				this.noDataFlag = false
				this.$http.get(apis.attentionList, this.listQuery).then(res => {
					if (res.data.code === 200) {
						this.noDataFlag = true
						this.attentionList = this.attentionList.concat(res.data.result.records)
						this.loadStatus.splice(this.current, 1, "loadmore")
					}
				})
			},
			clkFollowData(item) {
				let url = item.attentionFlag !== '1' ? apis.attention : apis.cancelAttention
				this.$http.post(url, { authorId: item.id }).then(res => {
					if (res.data.code === 200) {
						item.attentionFlag = item.attentionFlag === '1' ? '0' : '1'
					}
				})
				// 
			},
			reachBottom() {
				// 此tab为空数据
				this.loadStatus.splice(this.current, 1, "loading")
				this.listQuery.pageNo += 1
				this.getList()
			},
			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
				this.attentionList = []
				this.listQuery.pageNo = 1
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				this.listQuery.type = current + 1
				this.listQuery.pageNo = 1
				this.attentionList =  []
				this.getList()
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	/* 	page {
		height: 100%;
		background-color: #f2f2f2;
	} */

	/* #endif */
</style>

<style lang="scss" scoped>
@import "uview-ui/index.scss";
	.follow-count {
		font-size: 31rpx;
		font-family: SimHei;
		font-weight: 400;
		line-height: 40rpx;
		color: #4D5B80;
		margin-left: 29rpx;
		margin-bottom: 20rpx;
		opacity: 1;
	}

	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;
			border-bottom: 2rpx solid #BFBFBF;
			padding-bottom: 35rpx;
			padding-top: 25rpx;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				display: flex;
				flex-flow: column nowrap;
				flex-grow: 2;

				.title-line {
					// background-color: red;
					display: flex;
					flex-flow: row nowrap;

					.title {
						font-size: $title-font;
						flex-shrink: 2;
						width: 350rpx;
						color: #4D5B80;
						opacity: 1;

						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						margin-top: 4rpx;
					}

					.title-time {
						flex-grow: 2;
						font-size: 23rpx;
						font-family: SimHei;
						font-weight: 400;
						color: #949494;
						opacity: 1;
						margin-left: 10rpx;
						text-align: right;
					}
				}

				.info-line {
					margin-top: 0rpx;


					text {
						font-size: $artical-title-font;
						font-family: SimHei;
						font-weight: 400;
						color: #4D5B80;
						opacity: 1;

						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						// text-align: justify;
					}
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}


			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;

				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}

			.btn-follow {
				width: 120rpx;
				height: 40rpx;
				background: #3FA7FF;
				box-shadow: -4rpx -4rpx 12rpx #FFFFFF;
				opacity: 1;
				border-radius: 8rpx;

				font-size: 23rpx;
				font-family: SimHei;
				font-weight: 400;
				line-height: 31rpx;
				color: #E9EBF4;
				opacity: 1;

				// background: #E9EBF4;
			}

			.btn-nofollow {
				width: 120rpx;
				height: 40rpx;
				background: #E9EBF4;
				box-shadow: -4rpx -4rpx 12rpx #FFFFFF;
				opacity: 1;
				border-radius: 8rpx;

				font-size: 23rpx;
				font-family: SimHei;
				font-weight: 400;
				line-height: 31rpx;
				color: #4D5B80;
				opacity: 1;

				// background: #E9EBF4;
			}

		}

		.item-jubao {
			display: flex;
			flex-flow: nowrap column;
			margin: 20rpx 0 0;
			border-bottom: 2rpx solid #BFBFBF;
			padding-bottom: 35rpx;
			padding-top: 25rpx;

			.jubao-text {
				font-size: 31rpx;
				font-family: SimHei;
				font-weight: 400;
				line-height: 40rpx;
				color: #4D5B80;
				margin: 20rpx 18rpx;
				opacity: 1;
			}

			.jubao-time {
				align-self: flex-end;
				font-size: 23rpx;
				font-family: SimHei;
				font-weight: 400;
				color: #949494;
				opacity: 1;
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
	.no-data-wrapper {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 228rpx;
		.no-image {
			width: 369rpx;
			height: 229rpx;	
			margin-bottom: 43rpx;
		}
		.text-top {
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #212121;
			margin-bottom: 34rpx;
		}
		.text-bottom {
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #707070;
		}
	}
</style>
